package cn.fintecher.pangolin.service.dataimp.web;

import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.service.dataimp.model.WaitHandleListModel;
import cn.fintecher.pangolin.service.dataimp.model.request.AddRemarkRequest;
import cn.fintecher.pangolin.service.dataimp.model.response.CommentModel;
import cn.fintecher.pangolin.service.dataimp.service.HomeNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/homeNoticeController")
@Api(value = "公告首页", description = "公告首页")
public class HomeNoticeController extends BaseController {
    @Autowired
    private HomeNoticeService homeNoticeService;

    @GetMapping("/getComment")
    @ApiOperation(value = "查询备忘录", notes = "查询备忘录")
    public ResponseEntity<List<CommentModel>> getComment(@RequestHeader(value = "X-UserToken") String token) {
        List<CommentModel> responses = homeNoticeService.getComment(token);
        return ResponseEntity.ok().body(responses);
    }

    @GetMapping("/getWaitHandleList")
    @ApiOperation(value = "查询待办事项", notes = "查询待办事项")
    public ResponseEntity<WaitHandleListModel> getWaitHandleList(@RequestHeader(value = "X-UserToken") String token) {
        WaitHandleListModel model = homeNoticeService.getWaitHandleList(token);
        return ResponseEntity.ok().body(model);
    }

    /**
     * 新增备忘录
     */
    @ApiOperation(value = "新增备忘录", notes = "新增备忘录")
    @PostMapping("/addRemark")
    public ResponseEntity<Void> addRemark(@RequestBody AddRemarkRequest request,
                                          @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to add remark,{}", request);
        homeNoticeService.addRemark(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改备忘录
     */
    @ApiOperation(value = "修改备忘录", notes = "修改备忘录")
    @PutMapping("/modifyRemark")
    public ResponseEntity<Void> modifyRemark(@RequestBody AddRemarkRequest request,
                                             @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to modify remark,{}", request);
        homeNoticeService.modifyRemark(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除备忘录
     */
    @ApiOperation(value = "删除备忘录", notes = "删除备忘录")
    @DeleteMapping("/deleteRemark/{id}")
    public ResponseEntity<Void> deleteRemark(@PathVariable(value = "id", required = true) String id) {
        log.info("REST request to delete remark,{}", id);
        homeNoticeService.deleteRemark(id);
        return ResponseEntity.ok().build();
    }
}
